home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SPACE 1
/
SPACE - Library 1 - Volume 1.iso
/
program
/
386
/
algrtest
/
pushzero.s
< prev
next >
Wrap
Text File
|
1985-11-19
|
7KB
|
167 lines
; Program Name: PUSHZERO.S
; Version: 1.003
; Assembly Instructions:
; Assemble in AssemPro PC-relative mode and save with a TOS extension.
; Execution Instructions:
; Execute from the desktop; or execute SPAWN.TTP, type PUSHZERO.TOS on
; its command line and view this program's output in PUSHZERO.DAT.
; Program Function:
; For each of the three methods of pushing $0 onto the stack discussed in
; chapter two, calculates the memory occupied by each instruction, and
; calculates the execution time in milliseconds required for 50,000
; executions of each.
; Then, in order to emphasize the comparison for a more practical type of
; application, the one statement in the third algorithm that needs be
; executed only once, before the execution of the loop, is placed outside
; of the loop, and the time for 50,000 executions of the third method is
; repeated.
calculate_program_size:
lea -$102(pc), a1 ; Fetch basepage start address.
lea program_end, a0 ; Fetch program end address.
adda.l #100512, a0 ; Attach large stack space to end of program.
; NOTE: The above method of declaring stack space at the end of this program is
; preferable to that which I have been using because, if a label were
; used to declare the stack in the bss section, then the label used
; to mark the end of the program would be too far to permit the program
; to be assembled in AssemPro's PC-relative mode.
movea.l a0, a7 ; Point A7 to this program's stack.
trap #6 ; Return unused memory to op system.
print_heading:
lea heading, a0
bsr print_string
push_method_1:
lea header_1, a0
bsr print_string
move.l #49999, d7 ; D7 is counter for the push loop.
trap #3 ; Fetch start time.
move.l d0, d3 ; Save start_time in D3.
push_1_loop: ; Marks start of instruction in the loop.
clr.w -(sp) ; Instruction in the loop.
memory_1: ; Marks end of instruction in the loop.
dbra d7, push_1_loop ; Loop 50000 times.
trap #3 ; Fetch end time.
sub.l d3, d0 ; Subtract start time from end time.
trap #10 ; Convert to decimal milliseconds and print.
adda.l #100000, sp ; Reset stack pointer to top of stack.
print_method_1_requisite_memory:
lea header_5, a0 ; Print requisite memory header.
bsr print_string
lea memory_1, a0 ; Calculate number of bytes occupied by the
lea push_1_loop, a1 ; instruction in the loop.
suba.l a1, a0
bsr print_requisite_memory
push_method_2:
lea header_2, a0
bsr print_string
move.l #49999, d7 ; D7 is counter for the push loop.
trap #3 ; Fetch start time.
move.l d0, d3 ; Save start_time in D3.
push_2_loop: ; Marks start of instruction in the loop.
move.w #0, -(sp) ; Instruction in the loop.
memory_2: ; Marks end of instruction in the loop.
dbra d7, push_2_loop ; Loop 50000 times.
trap #3 ; Fetch end time.
sub.l d3, d0 ; Subtract start time from end time.
trap #10 ; Convert to decimal milliseconds and print.
adda.l #100000, sp ; Reset stack pointer to top of stack.
print_method_2_requisite_memory:
lea header_6, a0 ; Print requisite memory header.
bsr.s print_string
lea memory_2, a0 ; Calculate number of bytes occupied by the
lea push_2_loop, a1 ; instruction in the loop.
suba.l a1, a0
bsr.s print_requisite_memory
push_method_3:
lea header_3, a0
bsr.s print_string
move.l #49999, d7 ; D7 is counter for the push loop.
trap #3 ; Fetch start time.
move.l d0, d3 ; Save start_time in D3.
push_3_loop: ; Marks start of instructions in the loop.
moveq #0, d0 ; There are two instructions in the loop.
move.w d0, -(sp) ;
memory_3: ; Marks end of instructions in the loop.
dbra d7, push_3_loop ; Loop 50000 times.
trap #3 ; Fetch end time.
sub.l d3, d0 ; Subtract start time from end time.
trap #10 ; Convert to decimal milliseconds and print.
adda.l #100000, sp ; Reset stack pointer to top of stack.
print_method_3_requisite_memory:
lea header_7, a0 ; Print requisite memory header.
bsr.s print_string
lea memory_3, a0 ; Calculate number of bytes occupied by the
lea push_3_loop, a1 ; instructions in the loop.
suba.l a1, a0
bsr.s print_requisite_memory
modified_push_method_3:
lea header_4, a0
bsr.s print_string
move.l #49999, d7 ; D7 is counter for the push loop.
trap #3 ; Fetch start time.
move.l d0, d3 ; Save start_time in D3.
moveq #0, d0 ; Prestore $0 in D0.
push_4_loop:
move.w d0, -(sp) ; Contents of D0 onto the stack.
dbra d7, push_4_loop ; Loop 50000 times.
trap #3 ; Fetch end time.
sub.l d3, d0 ; Subtract start time from end time.
trap #10 ; Convert to decimal milliseconds and print.
adda.l #100000, sp ; Reset stack pointer to top of stack.
terminate:
trap #8
;
; SUBROUTINES
;
print_requisite_memory:
move.l a0, d1
trap #4
bsr.s print_string
lea header_8, a0
bsr.s print_string
rts
print_string: ; Expects address of string to be in A0.
move.l a0, -(sp) ; Push address of string onto stack.
move.w #9, -(sp) ; Function = c_conws = GEMDOS $9.
trap #1 ; GEMDOS call
addq.l #6, sp ; Reset stack pointer to top of stack.
rts
data
heading: dc.b $D,$A,"PUSHZERO Execution Results",$D,$A,$D,$A,0
header_1: dc.b " Elapsed time for clr.w -(sp): ",0
header_2: dc.b " Elapsed time for move.w #0, -(sp): ",0
header_3: dc.b " Elapsed time for moveq #0, d0",$D,$A
dc.b " move.w d0, -(sp): ",0
header_4: dc.b " Time for only move.w d0, -(sp): ",0
header_5: dc.b " Requisite memory: ",0
header_6: dc.b " Requisite memory: ",0
header_7: dc.b " Requisite memory: ",0
header_8: dc.b " bytes",$D,$A,$D,$A,0
bss
align
program_end: ds.l 0
end